package cn.iocoder.yudao.module.member.controller.app.cardsecurity;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
import cn.iocoder.yudao.module.member.controller.app.cardsecurity.vo.ExchangeConfigRespVO;
import cn.iocoder.yudao.module.member.dal.dataobject.cardsecurity.ExchangeConfigDO;
import cn.iocoder.yudao.module.member.service.cardsecurity.ExchangeConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.ibatis.annotations.Param;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;


@Tag(name = "前端 - 兑换站点配置")
@RestController
@RequestMapping("/exchange/config")
@Validated
public class ExchangeConfigController {

    @Resource
    private ExchangeConfigService exchangeConfigService;

    @PostMapping("/create")
    @Operation(summary = "创建兑换站点配置")
    @PreAuthenticated
    public CommonResult<Long> createConfig(@Valid @RequestBody ExchangeConfigRespVO createReqVO) {
        return success(exchangeConfigService.createConfig(createReqVO));
    }


//        @DeleteMapping("/delete")
//        @Operation(summary = "删除兑换站点配置")
//        @Parameter(name = "id", description = "编号", required = true)
//        @PreAuthorize("@ss.hasPermission('exchenge:config:delete')")
//        public CommonResult<Boolean> deleteConfig(@RequestParam("id") Long id) {
//                exchangeConfigService.deleteConfig(id);
//        return success(true);
//        }

    @GetMapping("/get")
    @Operation(summary = "获得兑换站点配置")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthenticated
    public CommonResult<ExchangeConfigRespVO> getConfig() {
        ExchangeConfigDO config = exchangeConfigService.getConfig();
        return success(BeanUtils.toBean(config, ExchangeConfigRespVO.class));
    }
    @GetMapping("/getByPrefix")
    @Operation(summary = "更具域名获得兑换站点配置")
    @Parameter(name = "bindDomainName", description = "分销域名", required = true, example = "1024")
    public CommonResult<ExchangeConfigRespVO> getByPrefix( @Param("Prefix")  String prefix) {
        ExchangeConfigDO config = exchangeConfigService.getByPrefix(prefix);
        return success(BeanUtils.toBean(config, ExchangeConfigRespVO.class));
    }
}

